
package com.ami.kvm.jviewer.kvmpkts;

import com.ami.kvm.jviewer.Debug;
import com.ami.kvm.jviewer.JViewer;
import com.ami.kvm.jviewer.communication.Client;
import com.ami.kvm.jviewer.communication.NWListener;
import com.ami.kvm.jviewer.gui.*;
import com.ami.kvm.jviewer.hid.USBMessage;
import com.ami.kvm.jviewer.jvvideo.JVVideo;
import com.ami.vmedia.VMApp;
import com.ami.vmedia.gui.VMDialog;

import javax.swing.*;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public class KVMClient extends Client {
	public static final int MAX_FRAGMENT_SIZE = 4608000;
	public static final int USER_DATA_LENGTH = 134;
	private static final int TIMEOUT_VALUE = 600000;
	public IVTPPktHdr m_pktHdr;
	public short m_fragNum;
	public ByteBuffer m_ctrlMsg;
	private HeaderReader m_hdrReader;
	private FragNumReader m_fragNumReader;
	private FragReader m_fragReader;
	private CtrlReader m_ctrlReader;
	private NullReader m_nullReader;
	private KVMReader m_reader;
	private JVVideo m_vidClnt;
	private NWListener m_NWListener;
	private volatile Thread m_NWThread;
	private boolean m_redirection = false;
	private KMCrypt m_kmCrypt;
	private boolean m_encrypt = false;

	private static String[] userData;

	private static int numUsers = 0;

	public static final int INVALID_SESSION = 0;

	public static final int VALID_SESSION = 1;
	public static final int KVM_DISABLED = 2;
	public static final int STOP_SESSION_IMMEDIATE = 2;
	public static final int INVALID_VIDEO_SESSION_INFO = 3;
	public static final int INVALID_CDROM_SESSION_TOKEN = 4;
	public static final int INVALID_FLOPPY_SESSION_TOKEN = 5;
	public static boolean DISABLE_ENCRPT_FLAG = false;
	public static final int STOP_SESSION_CONF_CHANGE = 5;
	public static final int STOP_SESSION_WEB_LOGOUT = 7;
	public static final int STOP_SESSION_LICENSE_EXP = 8;
	public static final int STOP_SESSION_TIMED_OUT = 9;
	public static final int STOP_SESSION_KVM_DSCONNECT = 10;
	public static final int STOP_SESSION_WEBSERVER_RESTART = 11;
	public IVTPPktHdr m_pktPreLoginHdr = null;

	public static final int HOST_LOCK_FEATURE_DISABLED = 0;

	public static final int HOST_LOCK_FEATURE_ENABLED = 1;

	public static final byte GET_HOST_LOCK_STATUS = 2;

	public static final byte MAX_SESSION_REACHED = 0;
	public static final byte SAME_KVM_CLIENT_USER = 1;
	public static final int TERMINATE_SESSION_PKT_SIZE = 5;
	public static final byte VGA_DAC_TURN_OFF = 0;
	public static final byte VGA_DAC_TURN_ON = 1;
	private boolean m_bUseSSL = false;
	public boolean m_isBlank = false;
	private boolean Host_OS_shutdown = false;

	private long m_startTS;
	private long m_stopTS;
	private ConfPkt[] confPacket = null;
	private UserDataPacket userDataPacket = null;

	private short hostLockStatus = -1;
	byte hostLockFeatureStatus = 1;
	private boolean stopSignalReceived = false;

	public KVMClient(byte[] paramArrayOfByte, int paramInt, JVVideo paramJVVideo, boolean paramBoolean) {
		super(paramArrayOfByte, paramInt);
		this.m_vidClnt = paramJVVideo;
		this.m_hdrReader = new HeaderReader(this);
		this.m_fragNumReader = new FragNumReader(this);
		this.m_fragReader = new FragReader(this);
		this.m_ctrlReader = new CtrlReader(this);
		this.m_nullReader = new NullReader(this);

		this.m_bUseSSL = paramBoolean;
		this.m_reader = this.m_hdrReader;
		this.m_kmCrypt = new KMCrypt();
	}

	public void onReadEvent() {
		Socket localSocket = getSocket();
		if (JViewer.isKVMReconnectEnabled()) {
			if (JViewerApp.getInstance().getLocalport() != localSocket.getLocalPort())
				return;
		}
		int i = this.m_reader.read(localSocket);
		JVFrame localJVFrame = JViewerApp.getInstance().getMainWindow();
		if (-1 == i) {
			try {
				if ((JViewer.isKVMReconnectEnabled()) && ((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp()))) {
					if ((JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPING)
							&& (JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPED)) {

						if (!JViewerApp.getInstance().getRetryConnection()) {
							JViewerApp.getInstance().onReconnect();
						}
					}
				} else {
					Thread.sleep(1000L);
				}
			} catch (Exception localException) {
				Debug.out.println(localException);
			}
			if (!JViewer.isKVMReconnectEnabled()) {

				if (!JViewer.isWebPreviewer()) {
					JViewerApp.getInstance().setRedirectionStatus(JViewerApp.REDIR_STOPPED);
					JOptionPane.showMessageDialog(localJVFrame, LocaleStrings.getString("2_1_KVMCLIENT"),
							LocaleStrings.getString("2_2_KVMCLIENT"), 0);

					JViewerApp.getInstance().getMainWindow().windowClosed();
				}

			}
		} else if (JViewer.isKVMReconnectEnabled()) {
			JViewerApp.getInstance().setLastPcktRecvd();
		}
	}

	public void setState(KVMReader paramKVMReader) {
		this.m_reader = paramKVMReader;
	}

	public HeaderReader getHdrReader() {
		return this.m_hdrReader;
	}

	public FragNumReader getFragNumReader() {
		return this.m_fragNumReader;
	}

	public FragReader getFragReader() {
		return this.m_fragReader;
	}

	public CtrlReader getCtrlReader() {
		return this.m_ctrlReader;
	}

	public NullReader getNullReader() {
		return this.m_nullReader;
	}

	public boolean onNewFrame(ByteBuffer paramByteBuffer) {
		if (JViewerApp.getInstance().m_refresh) {
			JViewerApp.getInstance().m_refresh = false;
			JViewerApp.getInstance().OnVideoPauseRedirection();
		}

		if (this.m_vidClnt.onNewFrame(paramByteBuffer) != 0) {
			Debug.out.println("onNewFrame failed.");
			return false;
		}

		return true;
	}

	public void onControlMessage() {
		Debug.out.println("CMDTYPE::" + this.m_pktHdr.type);

		if (JViewer.isKVMReconnectEnabled()) {
			JViewerApp.getInstance().setLastPcktRecvd();
		}

		if ((JViewerApp.getOEMManager() != null) && (JViewerApp.getOEMManager().getOEMKvmClient() != null)
				&& (JViewerApp.getOEMManager().getOEMKvmClient().handleControlPackets(this.m_pktHdr,
						this.m_ctrlMsg) == 1)) {
			Debug.out.println("OEM handled CMDTYPE::" + this.m_pktHdr.type);
			return;
		}

		Object localObject1;
		Object localObject2;
		byte b4;
		switch (this.m_pktHdr.type) {
		case 9:
			Debug.out.println("*** Blank screen");
			if (!this.m_isBlank) {
				this.m_vidClnt.onBlankScreen();
				this.m_isBlank = true;
			}
			break;
		case 8:
			Debug.out.println("*** Stop session Status : " + this.m_pktHdr.status());
			this.stopSignalReceived = true;
			if (JViewer.isKVMReconnectEnabled()) {
				JViewerApp.getInstance().setSessionLive(false);
			}
			if (JViewerApp.getInstance().getKVMShareDialog() != null) {
				if (KVMSharing.KVM_REQ_GIVEN == 0) {
					if (JViewerApp.getInstance().getKVMShareDialog().getKVMShareResponseDialog() != null) {
						JViewerApp.getInstance().getKVMShareDialog().disposeKVMShareResponseDialog();
					}
				}
			}
			JViewerApp.getInstance().OnVideoStopRedirection();
			JViewerApp.getInstance().getM_frame().windowClosed();
			if (this.m_pktHdr.status() == 5) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_3_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			} else if (this.m_pktHdr.status() == 7) {
				if (JViewer.isjviewerapp()) {
					JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
							LocaleStrings.getString("2_5_KVMCLIENT") + JViewer.getTitle()
									+ LocaleStrings.getString("2_22_KVMCLIENT"),
							LocaleStrings.getString("2_4_KVMCLIENT"), 0);
				}
			} else if (this.m_pktHdr.status() == 2) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_6_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			} else if (this.m_pktHdr.status() == 8) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_26_KVMCLIENT") + LocaleStrings.getString("2_6_KVMCLIENT"),
						LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			} else if (this.m_pktHdr.status() == 9) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_27_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			} else if (this.m_pktHdr.status() == 10) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_28_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			} else if (this.m_pktHdr.status() == 11) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_30_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);
			}
			JViewer.exit(0);
			break;
		case 14:
			Debug.out.println("*** Encryption Status");
			JViewerApp.getInstance().OnEncryptionStatus();
			break;
		case 15:
			Debug.out.println("*** Initial Encryption Status");
			JViewerApp.getInstance().OnInitialEncryptionStatus();
			break;
		case 10:
			Debug.out.println("*** Get Mouse Mode Response");
			JViewerApp.getInstance().OnGetMouseMode(this.m_ctrlMsg.get());
			break;
		case 19:
			Debug.out.println("*** ADVISER_VALIDATE_VIDEO_SESSION_RESPONSE:" + this.m_pktHdr.pktSize);
			byte b1 = this.m_ctrlMsg.get();
			byte b2 = -1;
			if (this.m_pktHdr.pktSize > 1) {
				b2 = this.m_ctrlMsg.get();
			}
			JViewerApp.getInstance().OnValidateVideoSessionResp(b1, b2);
			break;
		case 20:
			if ((!JViewer.isWebPreviewer()) || (!JViewer.isBSODViewer())) {
				byte b3 = this.m_ctrlMsg.get();

				if (!JViewerView.Lost_focus_flag) {
					JViewerApp.getInstance().onKeybdLED(b3);
					JViewerApp.getInstance().getM_wndFrame().getM_status().setKeyboardLEDStatus(b3);
					JViewerApp.getInstance().getM_fsFrame().getM_menuBar().getLedStatusBar().setLEDStatus(b3);
				}
			}
			break;

		case 23:
			if (JViewer.isWebPreviewer()) {
				JViewerApp.getInstance().onSendWebPreviewerSession();
			} else {
				if (this.m_pktHdr.pktSize > 0) {
					localObject1 = null;
					localObject1 = new byte[this.m_pktHdr.pktSize];
					this.m_ctrlMsg.get((byte[]) localObject1);
					localObject2 = new String((byte[]) localObject1);
					if (!JViewerApp.getInstance().getRetryConnection()) {
						if (null != localObject2) {
							int i = 0;
							int j = 48;
							int k = this.m_pktHdr.pktSize / j;
							String[] arrayOfString = new String[k];

							for (int m = 0; m < k; m++) {
								i = m * j;
								arrayOfString[m] = ((String) localObject2).substring(i, i + j).trim();
							}
							try {
								if (null == JViewerApp.getInstance().getMacAddress(2, arrayOfString)) {

									JVFrame localJVFrame = JViewerApp.getInstance().getMainWindow();

									JViewerApp.getInstance().getKVMClient().setM_redirection(true);
									JViewerApp.getInstance().OnVideoStopRedirection();

									JOptionPane.showMessageDialog(localJVFrame,
											LocaleStrings.getString("D_30_JVAPP") + JViewer.getIp()
													+ LocaleStrings.getString("D_31_JVAPP"),
											LocaleStrings.getString("D_32_JVAPP"), 1);

									JViewerApp.getInstance().OnVideoExit();
								}
							} catch (Exception localException3) {
								localException3.printStackTrace();
							}
						}
					}
				}

				JViewerApp.getInstance().OnsendWebsessionToken();
			}
			break;
		case 22:
			JViewerApp.getInstance().OnVideoStopRedirection();
			if (this.m_pktHdr.status() == 0) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("2_11_KVMCLIENT"), LocaleStrings.getString("2_4_KVMCLIENT"), 0);

			} else if (this.m_pktHdr.status() == 1) {
				JOptionPane.showMessageDialog(JViewerApp.getInstance().getRCView(),
						LocaleStrings.getString("D_30_JVAPP") + JViewer.getIp() + LocaleStrings.getString("D_31_JVAPP"),
						LocaleStrings.getString("D_32_JVAPP"), 1);
			}

			if (JViewer.isStandalone()) {
				JViewer.exit(0);
			} else
				JViewerApp.getInstance().getMainWindow().dispose();
			break;
		case 33:
			JViewerApp.getInstance().onStopConcurrentSession();
			break;
		case 32:
		case 50:
			if (this.m_pktHdr.pktSize > 0) {
				localObject1 = null;
				localObject2 = null;
				localObject2 = new byte[134];
				this.m_ctrlMsg.get((byte[]) localObject2);
				byte[] arrayOfByte = new byte[64];
				localObject1 = ByteBuffer.wrap((byte[]) localObject2);
				((ByteBuffer) localObject1).order(ByteOrder.LITTLE_ENDIAN);
				((ByteBuffer) localObject1).get(arrayOfByte);
				KVMSharing.KVM_CLIENT_USERNAME = new String(arrayOfByte).trim();
				arrayOfByte = new byte[65];
				((ByteBuffer) localObject1).get(arrayOfByte);
				KVMSharing.KVM_CLIENT_IP = new String(arrayOfByte).trim();
				KVMSharing.KVM_CLIENT_SESSION_INDEX = Integer.toString(((ByteBuffer) localObject1).get());
				KVMSharing.KVM_CLIENT_IPMI_PRIV = ((ByteBuffer) localObject1).getInt();
				Debug.out.println(KVMSharing.KVM_CLIENT_USERNAME + " : " + KVMSharing.KVM_CLIENT_IP + " : "
						+ KVMSharing.KVM_CLIENT_SESSION_INDEX + " :: " + KVMSharing.KVM_CLIENT_IPMI_PRIV);
			}

			if (this.m_pktHdr.type == 32) {
				JViewerApp.getInstance().OnKvmPrevilage(this.m_pktHdr.status);
			} else {
				JViewerApp.getInstance().onGetFullPermissionRequest(this.m_pktHdr.status);
			}

			JViewerApp.getInstance().getJVMenu().updateUserMenu();
			break;
		case 27:
			JViewerApp.getInstance().setWebPreviewerCaptureStatus(this.m_ctrlMsg.get());
			break;
		case 34:
			if ((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp())) {
				b4 = (byte) this.m_pktHdr.status();

				if (!this.Host_OS_shutdown) {
					Debug.out.println("POWER STATUS : " + b4);
					JViewerApp.getInstance().onGetPowerControlStatus(b4);

				} else if (b4 == 1) {
					try {
						Thread.sleep(2000L);
						sendPowerStatusRequest();
					} catch (Exception localException1) {
						Debug.out.println(localException1);
					}
				} else {
					JViewerApp.getInstance().onGetPowerControlStatus(b4);
					this.Host_OS_shutdown = false;
				}
			}
			break;

		case 36:
			b4 = (byte) this.m_pktHdr.status();
			Debug.out.println("RESPONSE : " + b4);
			JViewerApp.getInstance().onPowerControlResponse(b4);
			break;
		case 37:
			readConfServiceData();
			break;
		case 38:
			try {
				onreadmouse_media_count();
			} catch (Exception localException2) {
				Debug.out.println(localException2);
			}

		case 39:
			if ((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp())) {
				readUserData();
				JViewerApp.getInstance().getJVMenu().updateUserMenu();
				sendFullScreenRequest();
			}
			break;
		case 40:
			processUserMacroPacket(this.m_ctrlMsg);
			break;
		case 49:
			JViewerApp.getInstance().onGetIPMICommandResponse(this.m_ctrlMsg, this.m_pktHdr.status);
			break;
		case 52:
			JFrame localJFrame = JViewer.getMainFrame();
			short s = this.m_pktHdr.status();
			if (s != this.hostLockStatus) {
				JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoHostDisplayUnlock", false);
				JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoHostDisplayLock", false);
				if (s == 0) {
					if (KVMSharing.KVM_REQ_GIVEN == 0) {
						JViewerApp.getInstance().changeHostDisplayLockStatus((short) 0);
					} else
						JViewerApp.getInstance().getM_wndFrame().getToolbar().turnOnHostDisplayButton(true);
					if ((this.hostLockStatus > 0) && (this.hostLockStatus != 2)) {
						InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_23_KVMCLIENT"),
								LocaleStrings.getString("2_25_KVMCLIENT"), 1);
					}

					setHostLockStatus(s);
					JViewerApp.getInstance().getSockvmclient().changeVideoEngineVGAStatus((byte) 1);
				} else if (s == 1) {

					if (KVMSharing.KVM_REQ_GIVEN == 0) {
						JViewerApp.getInstance().changeHostDisplayLockStatus((short) 1);
					} else
						JViewerApp.getInstance().getM_wndFrame().getToolbar().turnOnHostDisplayButton(false);
					if ((this.hostLockStatus >= 0) && (this.hostLockStatus != 1) && (this.hostLockStatus != 3)) {
						InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_24_KVMCLIENT"),
								LocaleStrings.getString("2_25_KVMCLIENT"), 1);
					}

					setHostLockStatus(s);
					JViewerApp.getInstance().getSockvmclient().changeVideoEngineVGAStatus((byte) 0);
				} else if (s == 2) {
					JViewerApp.getInstance().changeHostDisplayLockStatus((short) 2);
					if ((this.hostLockStatus > 0) && (this.hostLockStatus != 3)) {
						InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_29_KVMCLIENT"),
								LocaleStrings.getString("2_25_KVMCLIENT"), 1);
					}

					setHostLockStatus(s);
				} else if (s == 3) {
					JViewerApp.getInstance().changeHostDisplayLockStatus((short) 3);
					if ((this.hostLockStatus >= 0) && (this.hostLockStatus != 1) && (this.hostLockStatus != 3)) {
						InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_24_KVMCLIENT"),
								LocaleStrings.getString("2_25_KVMCLIENT"), 1);
					}

					setHostLockStatus(s);
				}
			}
			break;
		case 53:
			JViewerApp.getInstance().onMediaLicenseStatus((byte) this.m_pktHdr.status());
			break;
		case 56:
			getVMediaFreeInstanceStatus(this.m_ctrlMsg);
			break;
		case 57:
			break;
		case 59:
			JViewerApp.getInstance().onConnFailed();
			break;
		case 11:
		case 12:
		case 13:
		case 16:
		case 17:
		case 18:
		case 21:
		case 24:
		case 25:
		case 26:
		case 28:
		case 29:
		case 30:
		case 31:
		case 35:
		case 41:
		case 42:
		case 43:
		case 44:
		case 45:
		case 46:
		case 47:
		case 48:
		case 51:
		case 54:
		case 55:
		case 58:
		default:
			JViewerApp.getInstance().getSockvmclient().onSocControlMessage(this.m_pktHdr, this.m_ctrlMsg);
		}
	}

	public void sendFullScreenRequest() {
		if (!this.m_redirection) {
			return;
		}

		OnFormIVTPHdr_Send((short) 11, 0, (short) 0);
	}

	public boolean redirection() {
		return this.m_redirection;
	}

	public int OnFormIVTPHdr_Send(short paramShort1, int paramInt, short paramShort2) {
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr(paramShort1, paramInt, paramShort2);
		int i = sendMessage(localIVTPPktHdr.array(), localIVTPPktHdr.size());
		if (i != localIVTPPktHdr.size()) {
			return -1;
		}
		return i;
	}

	public void resumeRedirection() {
		this.m_redirection = true;

		if (!this.m_redirection) {
			return;
		}
		OnFormIVTPHdr_Send((short) 6, 0, (short) 0);

		this.m_vidClnt.refresh();
		sendLEDRequest();
	}

	public void Stop_Cmd_Redirection() {
		if (!this.m_redirection) {
			return;
		}

		OnFormIVTPHdr_Send((short) 8, 0, (short) 0);
	}

	public void sendLEDRequest() {
		if (!this.m_redirection) {
			return;
		}

		OnFormIVTPHdr_Send((short) 20, 0, (short) 0);
	}

	public void sendPowerStatusRequest() {
		if (!this.m_redirection) {
			return;
		}
		OnFormIVTPHdr_Send((short) 34, 0, (short) 0);
	}

	public void sendPowerControlCommand(byte paramByte) {
		if ((paramByte == 5) || (paramByte == 0)) {
			this.Host_OS_shutdown = true;
		}
		Debug.out.println("sendPowerControlCommand, command = " + paramByte);
		OnFormIVTPHdr_Send((short) 35, 0, (short) paramByte);
	}

	// FIXME tianlin 开启视频转接
	public int startRedirection() {
		if (this.m_redirection) {
			return 0;
		}
		if (JViewer.isSinglePortEnabled()) {
			if (JViewer.isKVMReconnectEnabled()) {
				if (JViewerApp.getInstance().getRetryConnection()) {
					if (0 > JViewerApp.getInstance().getSinglePortKvm().startConnect()) {
						return -1;
					}
				}
				JViewerApp.getInstance()
						.setLocalport(JViewerApp.getInstance().getSinglePortKvm().getHttpsock().getLocalPort());
			}
			SetSocket(JViewerApp.getInstance().getSinglePortKvm().getHttpsock());

			String str = this.m_sock.getLocalAddress().toString();

			String[] arrayOfString = str.split("/");
			KVMSharing.KVM_CLIENT_OWN_IP = arrayOfString[1];

			if (KVMSharing.KVM_CLIENT_OWN_IP.compareToIgnoreCase("127.0.0.1") == 0) {
				try {
					KVMSharing.KVM_CLIENT_OWN_IP = InetAddress.getLocalHost().getHostAddress().toString();
				} catch (Exception localException) {
				}
			}

			if (KVMSharing.KVM_CLIENT_OWN_IP.compareToIgnoreCase("0.0.0.0") == 0) {
				KVMSharing.KVM_CLIENT_OWN_IP = getipv6IP();
			}
			Debug.out.println("SPKVM m_sock.socket().getLocalAddress()" + str.toString());

			Debug.out.println("SPKVM m_sock.socket().getLocalAddress()" + KVMSharing.KVM_CLIENT_OWN_IP);

		} else if (-1 == connectVideo(this.m_bUseSSL)) {
			return -1;
		}

		Debug.out.println("Video socket approval received");

		this.m_NWListener = new NWListener(this);
		this.m_NWThread = new Thread(this.m_NWListener, "listener");
		this.m_NWListener.startListener();
		this.m_NWThread.start();
		return 0;
	}

	public int OnValidVideoSession() {
		this.m_redirection = true;
		JViewerApp.getSoc_manager().getSOCApp().SOC_Session_validated();
		if ((!JViewer.isWebPreviewer()) && (!JViewer.isBSODViewer())) {
			sendPowerStatusRequest();
			onSendLockScreen((byte) 2);
			OnGetUserMacro();
			Debug.out.println("KVM Redirection Started!");
		}
		return 0;
	}

	private void OnGetUserMacro() {
		sendGetUserMacro();
	}

	public int sendGetUserMacro() {
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 40, 0, (short) 0);
		if (sendMessage(localIVTPPktHdr.array(), localIVTPPktHdr.size()) != localIVTPPktHdr.size())
			return 1;
		return 0;
	}

	public boolean isKMEncryptionEnabled() {
		return this.m_encrypt;
	}

	public void notifyEncryption(boolean paramBoolean) {
		if (!this.m_redirection)
			return;
		this.m_encrypt = paramBoolean;
	}

	public void stopRedirection() {
		if (!this.m_redirection) {
			if (JViewerApp.getInstance().GetRedirectionState() != JViewerApp.REDIR_STOPPING)
				return;
		}
		try {
			Thread.sleep(1000L);
		} catch (Exception localException1) {
			Debug.out.println(localException1);
		}

		VideoSocketclose();
		this.m_NWListener.destroyListener();
		this.m_redirection = false;
		try {
			this.m_vidClnt.reset();
		} catch (Exception localException2) {
			Debug.out.println(localException2);
		}
		this.m_kmCrypt.close();
	}

	public void pauseRedirection() {
		if (!this.m_redirection) {
			return;
		}
		OnFormIVTPHdr_Send((short) 4, 0, (short) 0);
		this.m_vidClnt.reset();
		this.m_redirection = false;
	}

	public void MediaRedirectionState(byte paramByte) {
		if (!this.m_redirection)
			return;
		OnFormIVTPHdr_Send((short) 24, 0, (short) paramByte);
	}

	public int read_data(Socket paramSocket, byte[] paramArrayOfByte) {
		int i = 0;
		int j = paramArrayOfByte.length;
		int k = -1;

		while (j != 0) {
			try {
				k = paramSocket.getInputStream().read(paramArrayOfByte, i, j);
			} catch (IOException localIOException) {
				Debug.out.println(localIOException);
				if ((JViewer.isKVMReconnectEnabled()) && ((JViewer.isjviewerapp()) || (JViewer.isStandAloneApp()))) {
					JViewerApp.getInstance().onReconnect();
				}
				return k;
			}

			if (k <= 0) {
				return k;
			}
			j -= k;
			i += k;
		}
		k = paramArrayOfByte.length;
		return k;
	}

	public int sendKMMessage(USBMessage paramUSBMessage) {
		if ((KVMSharing.KVM_REQ_GIVEN != 0) || (JViewerApp.getInstance().getPowerStatus() != 1)) {
			return -1;
		}

		if (this.m_redirection) {
			byte[] arrayOfByte;
			if ((this.m_encrypt == true) && (this.m_kmCrypt.isInitialized())) {
				arrayOfByte = paramUSBMessage.encryptedReport(this.m_kmCrypt);
			} else {
				arrayOfByte = paramUSBMessage.report();
			}
			if (JViewerApp.getInstance().getM_USBKeyRep().KeyBoardDataNull) {
				JViewerApp.getInstance().getM_USBKeyRep().KeyBoardDataNull = false;
				return 0;
			}
			if (arrayOfByte == null)
				return 0;
			if (sendMessage(arrayOfByte, arrayOfByte.length) != arrayOfByte.length) {
				Debug.out.println("Error sending USB Keyboard/Mouse packet");

				return -1;
			}
		}

		return 0;
	}

	public int SendKVMPrevilage(byte paramByte, String paramString) {
		ByteBuffer localByteBuffer1 = null;
		int i = -1;
		byte[] arrayOfByte1 = null;
		int j = -1;
		String str1 = null;
		String str2 = null;

		Debug.out.println("User2_status" + paramByte);
		short s = (short) (1 + (paramByte << 8));
		Debug.out.println("send_status" + s);
		j = paramString.indexOf(':');
		str1 = paramString.substring(0, j).trim();
		str2 = paramString.substring(j + 2, paramString.indexOf(':', j + 2)).trim();
		int k = Integer.parseInt(paramString.substring(paramString.lastIndexOf(':') + 1, paramString.length()).trim());

		arrayOfByte1 = new byte[64];
		arrayOfByte1 = str1.getBytes();
		localByteBuffer1 = ByteBuffer.allocate(134);
		localByteBuffer1.order(ByteOrder.LITTLE_ENDIAN);
		localByteBuffer1.position(0);
		localByteBuffer1.put(arrayOfByte1);
		for (j = localByteBuffer1.position(); j < 64; j++)
			localByteBuffer1.put((byte) 0);
		arrayOfByte1 = new byte[65];

		arrayOfByte1 = str2.getBytes();
		localByteBuffer1.put(arrayOfByte1);
		for (j = localByteBuffer1.position(); j < 129; j++)
			localByteBuffer1.put((byte) 0);
		localByteBuffer1.put((byte) k);
		localByteBuffer1.rewind();
		localByteBuffer1.position(0);
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 32, localByteBuffer1.limit(), s);

		ByteBuffer localByteBuffer2 = ByteBuffer.allocate(localIVTPPktHdr.size() + localIVTPPktHdr.pktSize());
		localByteBuffer2.position(0);
		localByteBuffer2.put(localIVTPPktHdr.array());
		localByteBuffer2.put(localByteBuffer1.array());
		localByteBuffer2.position(0);
		byte[] arrayOfByte2 = new byte[localByteBuffer2.limit()];
		localByteBuffer2.get(arrayOfByte2, 0, localByteBuffer2.limit());
		i = sendMessage(arrayOfByte2, arrayOfByte2.length);
		if (arrayOfByte2.length != i) {
			return -1;
		}
		return 0;
	}

	public int sendKVMFullPermissionRequest() {
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 50, 0, (short) 0);
		if (sendMessage(localIVTPPktHdr.array(), localIVTPPktHdr.size()) != localIVTPPktHdr.size()) {
			return -1;
		}
		return 0;
	}

	public int sendKeepAliveRequest() {
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 57, 0, (short) 0);
		try {
			if (sendMessage(localIVTPPktHdr.array(), localIVTPPktHdr.size()) != localIVTPPktHdr.size()) {
				return 0;
			}
			getSocket().getOutputStream().flush();
		} catch (IOException localIOException) {
			Debug.out.println(localIOException);
			return -1;
		}

		return 0;
	}

	public void checkReconnect() {
		if (!JViewerApp.getInstance().getRetryConnection()) {
			this.m_redirection = false;
			JViewerApp.getInstance().setSessionLive(false);
			JViewerApp.getInstance().setRetryConnection(true);
			JViewerApp.getInstance().OnVideoStopRedirection();
		} else {
			try {
				Thread.sleep(JViewer.getRetryInterval());
			} catch (InterruptedException localInterruptedException) {
				Debug.out.println(localInterruptedException);
			}
		}
		JViewerApp.getInstance().currentRetryCount += 1;
	}

	public int SendMouseMode(byte paramByte) {
		Debug.out.println("MouseMode" + paramByte);
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 28, 0, (short) paramByte);
		if (sendMessage(localIVTPPktHdr.array(), localIVTPPktHdr.size()) != localIVTPPktHdr.size())
			return 1;
		return 0;
	}

	public void setEncryption(boolean paramBoolean) {
		if (!this.m_redirection)
			return;
		if (paramBoolean) {
			this.m_encrypt = true;
			OnFormIVTPHdr_Send((short) 12, 0, (short) 0);
		} else {
			this.m_encrypt = false;
			DISABLE_ENCRPT_FLAG = true;
			OnFormIVTPHdr_Send((short) 13, 0, (short) 0);
		}
	}

	public KMCrypt getCrypt() {
		return this.m_kmCrypt;
	}

	public int setBandwidth(int paramInt) {
		if (!this.m_redirection) {
			return -1;
		}
		CfgBandwidth localCfgBandwidth = new CfgBandwidth(paramInt);
		if (localCfgBandwidth.size() != sendMessage(localCfgBandwidth.report(), localCfgBandwidth.size())) {
			Debug.out.println("Failed to send Config Bandwidth message");
			return -1;
		}
		return 0;
	}

	public int autoDetect() {
		if (!this.m_redirection) {
			return -1;
		}
		AutoDetectBw localAutoDetectBw = new AutoDetectBw(13107200);

		if (localAutoDetectBw.size() != sendMessage(localAutoDetectBw.report(), localAutoDetectBw.size())) {
			Debug.out.println("Failed to send auto detect message");
			return -1;
		}

		return 0;
	}

	public void onStartReading() {
		this.m_startTS = System.currentTimeMillis();
	}

	public void onStopReading() {
		this.m_stopTS = System.currentTimeMillis();
		int i = CfgBandwidth.determineBandwidth(this.m_stopTS - this.m_startTS);
		Debug.out.println("Time " + (this.m_stopTS - this.m_startTS) + ", Bandwidth " + i);
		String str = "unknown";
		JViewerApp.getInstance().OnOptionsBandwidth(i);

		switch (i) {
		case 13107200:
			str = "100mbps";
			break;

		case 1310720:
			str = "10mbps";
			break;

		case 131072:
			str = "1mbps";
			break;

		case 65536:
			str = "512kbps";
			break;

		case 32768:
			str = "256kbps";
		}

		JViewerApp.getInstance().updateBandwidthMsg(str);
	}

	public KVMReader getSocReader(short paramShort) {
		return (KVMReader) JViewerApp.getInstance().getSockvmclient().getSOCReader(paramShort);
	}

	public boolean isM_redirection() {
		return this.m_redirection;
	}

	public void setM_redirection(boolean paramBoolean) {
		this.m_redirection = paramBoolean;
	}

	public void processUserMacroPacket(ByteBuffer paramByteBuffer) {
		if (JViewerApp.getInstance().getAddMacro() == null) {
			JViewerApp.getInstance().setAddMacro(new AddMacro(paramByteBuffer));
		} else {
			JViewerApp.getInstance().getAddMacro().setMacroBuffer(paramByteBuffer);
		}
		JViewerApp.getInstance().getAddMacro().parseDataToMenu();

		if ((KVMSharing.KVM_REQ_GIVEN != 2) && (!KVMShareDialog.isMasterSession)) {
			JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("Add Hotkeys", true);
		}
	}

	public int sendUserMacroData(byte[] paramArrayOfByte) {
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 41, 960, (short) 0);

		ByteBuffer localByteBuffer = ByteBuffer.allocate(localIVTPPktHdr.size() + localIVTPPktHdr.pktSize());
		localByteBuffer.position(0);
		localByteBuffer.put(localIVTPPktHdr.array());

		localByteBuffer.put(paramArrayOfByte);
		localByteBuffer.position(0);
		byte[] arrayOfByte = new byte[localByteBuffer.limit()];
		localByteBuffer.get(arrayOfByte, 0, localByteBuffer.limit());
		if (arrayOfByte.length != sendMessage(arrayOfByte, arrayOfByte.length)) {
			return -1;
		}

		return 0;
	}

	public void readConfServiceData() {
		if (this.m_pktHdr.pktSize > 0) {
			byte[] arrayOfByte1 = new byte['ĝ'];
			this.m_ctrlMsg.get(arrayOfByte1);
			int i = 0;
			int k;
			if (this.confPacket == null) {
				this.confPacket = new ConfPkt[5];
				byte[] localObject = new byte[57];
				for (int j = 0; j < 5; j++) {
					for (k = 0; k < 57; k++) {
						localObject[k] = arrayOfByte1[(k + i)];
					}
					this.confPacket[j] = new ConfPkt((byte[]) localObject);
					i += 57;
				}
			} else {
				ConfPkt[] localObject = new ConfPkt[5];
				byte[] arrayOfByte2 = new byte[57];
				for (k = 0; k < 5; k++) {
					for (int m = 0; m < 57; m++) {
						arrayOfByte2[m] = arrayOfByte1[(m + i)];
					}
					localObject[k] = new ConfPkt(arrayOfByte2);
					compareConfData(localObject[k], k);
					i += 57;
				}
			}
		}
	}

	public void compareConfData(ConfPkt paramConfPkt, int paramInt) {
		if ((JViewer.isStandAloneApp()) && (paramConfPkt.getServiceName().equals("web")))
			return;
		String str = "";
		if (paramConfPkt.getCurrentState() != this.confPacket[paramInt].getCurrentState()) {
			if (paramConfPkt.getCurrentState() == 0) {
				str = str + "* " + LocaleStrings.getString("2_12_KVMCLIENT") + " : "
						+ LocaleStrings.getString("2_13_KVMCLIENT") + "\n";
			} else
				str = str + "* " + LocaleStrings.getString("2_12_KVMCLIENT") + " : "
						+ LocaleStrings.getString("2_14_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setCurrentState(paramConfPkt.getCurrentState());
			onChangeState(paramConfPkt, paramConfPkt.getServiceName());
		}
		if (!paramConfPkt.getInterfaceName().equals(this.confPacket[paramInt].getInterfaceName())) {
			str = str + "* " + LocaleStrings.getString("2_15_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setInterfaceName(paramConfPkt.getInterfaceName().toCharArray());
		}
		if (paramConfPkt.getNonSecureAccessPort() != this.confPacket[paramInt].getNonSecureAccessPort()) {
			str = str + "* " + LocaleStrings.getString("2_16_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setNonSecureAccessPort(paramConfPkt.getNonSecureAccessPort());
			onChangeNonSecurePort(paramConfPkt, paramConfPkt.getServiceName());
		}
		if (paramConfPkt.getSecureAccessPort() != this.confPacket[paramInt].getSecureAccessPort()) {
			str = str + "* " + LocaleStrings.getString("2_17_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setSecureAccessPort(paramConfPkt.getSecureAccessPort());
			onChangeSecurePort(paramConfPkt, paramConfPkt.getServiceName());
		}
		if (paramConfPkt.getSessionInactivityTimeout() != this.confPacket[paramInt].getSessionInactivityTimeout()) {
			str = str + "* " + LocaleStrings.getString("2_18_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setSessionInactivityTimeout(paramConfPkt.getSessionInactivityTimeout());
		}
		if (paramConfPkt.getMaxAllowedSessions() != this.confPacket[paramInt].getMaxAllowedSessions()) {
			str = str + "* " + LocaleStrings.getString("2_19_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setMaxAllowedSessions(paramConfPkt.getMaxAllowedSessions());
		}
		if (paramConfPkt.getMaxSessionInactivityTimeout() != this.confPacket[paramInt]
				.getMaxSessionInactivityTimeout()) {
			str = str + "* " + LocaleStrings.getString("2_20_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setMaxSessionInactivityTimeout(paramConfPkt.getMaxSessionInactivityTimeout());
		}
		if (paramConfPkt.getMinSessionInactivityTimeout() != this.confPacket[paramInt]
				.getMinSessionInactivityTimeout()) {
			str = str + "* " + LocaleStrings.getString("2_21_KVMCLIENT") + "\n";
			this.confPacket[paramInt].setMinSessionInactivityTimeout(paramConfPkt.getMinSessionInactivityTimeout());
		}
		if ((!str.equals(null)) && (str.length() != 0)) {
			this.confPacket[paramInt].showConfDataChangeMsg(str);
		}
	}

	public void onChangeState(ConfPkt paramConfPkt, String paramString) {
		if (paramString.equals("cd-media")) {
			JViewer.setCD_State(paramConfPkt.getCurrentState());
		}
		if (paramString.equals("fd-media")) {
			JViewer.setFD_State(paramConfPkt.getCurrentState());
		}
		if (paramString.equals("hd-media")) {
			JViewer.setHD_State(paramConfPkt.getCurrentState());
		}
	}

	public void onChangeSecurePort(ConfPkt paramConfPkt, String paramString) {
		if (!JViewerApp.getInstance().isM_bVMUseSSL())
			return;
		if (paramString.compareTo("cd-media") == 0) {
			JViewerApp.getInstance().setM_cdPort(paramConfPkt.getSecureAccessPort());
		}
		if (paramString.compareTo("fd-media") == 0) {
			JViewerApp.getInstance().setM_fdPort(paramConfPkt.getSecureAccessPort());
		}
		if (paramString.compareTo("hd-media") == 0) {
			JViewerApp.getInstance().setM_hdPort(paramConfPkt.getSecureAccessPort());
		}
		if (JViewerApp.getInstance().getVMDialog() != null)
			JViewerApp.getInstance().getVMDialog().setVisible(false);
	}

	public void onChangeNonSecurePort(ConfPkt paramConfPkt, String paramString) {
		if (JViewerApp.getInstance().isM_bVMUseSSL()) {
			return;
		}
		if (paramString.compareTo("cd-media") == 0) {
			JViewerApp.getInstance().setM_cdPort(paramConfPkt.getNonSecureAccessPort());
		}
		if (paramString.compareTo("fd-media") == 0) {
			JViewerApp.getInstance().setM_fdPort(paramConfPkt.getNonSecureAccessPort());
		}
		if (paramString.compareTo("hd-media") == 0) {
			JViewerApp.getInstance().setM_hdPort(paramConfPkt.getNonSecureAccessPort());
		}
		if (JViewerApp.getInstance().getVMDialog() != null) {
			JViewerApp.getInstance().getVMDialog().setVisible(false);
		}
	}

	private void onreadmouse_media_count() {
		boolean bool = false;
		int i = 0;
		byte[] arrayOfByte = new byte[this.m_pktHdr.pktSize()];
		this.m_ctrlMsg.get(arrayOfByte);
		ByteBuffer localByteBuffer = ByteBuffer.wrap(arrayOfByte);
		localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
		byte b = 0;
		int j = 0;
		int k = 0;
		int m = 0;
		int n = 0;
		int i1 = 0;
		int i2 = 0;
		int i3 = 0;
		int i4 = 0;
		int i5 = 0;
		int i6 = 0;
		int i7 = 0;
		int i8 = 0;
		VMDialog localVMDialog = JViewerApp.getInstance().getVMDialog();
		if (JViewer.isKVMReconnectEnabled()) {
			JViewer.setRetryCount(localByteBuffer.getInt());
			JViewer.setRetryInterval(localByteBuffer.getInt());
		}
		b = localByteBuffer.get();
		this.hostLockFeatureStatus = localByteBuffer.get();
		this.hostLockFeatureStatus = ((byte) (this.hostLockFeatureStatus & 0x1));

		j = localByteBuffer.getInt();
		k = localByteBuffer.getInt();
		m = localByteBuffer.getInt();
		n = localByteBuffer.getInt();
		i1 = localByteBuffer.getInt();
		i2 = localByteBuffer.getInt();
		i3 = localByteBuffer.getInt();
		i4 = localByteBuffer.getInt();
		localByteBuffer.getInt();
		localByteBuffer.getInt();
		i5 = localByteBuffer.getInt();
		i6 = localByteBuffer.getInt();
		i7 = localByteBuffer.getInt();
		i8 = localByteBuffer.getInt();

		JViewer.setPowerSaveMode((byte) i5);

		if (JViewer.getNum_CD() != i1) {
			i = 1;
		}

		if (JViewer.getNum_FD() != i2) {
			i = 1;
		}

		if (JViewer.getNum_HD() != i3) {
			i = 1;
		}

		if (i != 1) {
			if ((JViewer.getOEMFeatureStatus() & 0x80) == 128L) {

				if (JViewer.getKVM_Num_CD() != i6) {
					i = 1;
				}

				if (JViewer.getKVM_Num_FD() != i7) {
					i = 1;
				}

				if (JViewer.getKVM_Num_HD() != i8) {
					i = 1;
				}
			}
		}
		if (JViewerApp.getInstance().getRCView().GetUSBMouseMode() != b) {
			JViewerApp.getInstance().getRCView().removeKMListener();
			JViewerApp.getInstance().getRCView().USBsyncCursor(false);
			JViewerApp.getInstance().OnGetMouseMode(b);
		} else if (this.hostLockFeatureStatus == 1) {
			JViewerApp.getInstance().changeHostDisplayLockStatus(this.hostLockStatus);
		} else if (this.hostLockFeatureStatus != 1) {
			JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoHostDisplayUnlock", false);
			JViewerApp.getInstance().getJVMenu().notifyMenuStateEnable("VideoHostDisplayLock", false);

		} else if (i == 0) {
			bool = JViewerApp.getInstance().syncVMediaRedirection();
			if (bool)
				i = 1;
		}
		if (i != 0) {
			bool = JViewerApp.getInstance().syncVMediaRedirection();
			JFrame localJFrame = JViewer.getMainFrame();
			if ((JViewerApp.getInstance().getVMDialog() != null)
					&& (JViewerApp.getInstance().getVMDialog().isShowing())) {
				InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_7_KVMCLIENT"),
						LocaleStrings.getString("2_10_KVMCLIENT"), 1);

				if (bool) {
					JViewerApp.getInstance().getM_frame().stopVMediaRedirection(null);
				}
			} else if (bool) {
				InfoDialog.showDialog(localJFrame,
						LocaleStrings.getString("2_7_KVMCLIENT") + LocaleStrings.getString("2_9_KVMCLIENT"),
						LocaleStrings.getString("2_10_KVMCLIENT"), 1);

				JViewerApp.getInstance().getM_frame().stopVMediaRedirection(null);
			} else {
				InfoDialog.showDialog(localJFrame, LocaleStrings.getString("2_7_KVMCLIENT"),
						LocaleStrings.getString("2_10_KVMCLIENT"), 1);
			}

			if ((JViewer.getOEMFeatureStatus() & 0x80) == 128L) {

				JViewer.setKVM_Num_CD((byte) i6);
				JViewer.setKVM_Num_FD((byte) i7);
				JViewer.setKVM_Num_HD((byte) i8);
				JViewerApp.getInstance().setFreeCDNum(i6);
				JViewerApp.getInstance().setFreeFDNum(i7);
				JViewerApp.getInstance().setFreeHDNum(i8);
			} else {
				JViewer.setNum_CD((byte) i6);
				JViewer.setNum_FD((byte) i7);
				JViewer.setNum_HD((byte) i8);
				JViewerApp.getInstance().setFreeCDNum(i1);
				JViewerApp.getInstance().setFreeFDNum(i2);
				JViewerApp.getInstance().setFreeHDNum(i3);
			}

			if (localVMDialog != null)
				localVMDialog.reInitialize();
			VMApp.getInstance().getIUSBRedirSession().updateCDToolbarButtonStatus(false);
			VMApp.getInstance().getIUSBRedirSession().updateFDToolbarButtonStatus(false);
			VMApp.getInstance().getIUSBRedirSession().updateHDToolbarButtonStatus(false);

			JViewerApp.getInstance().updateFreeDeviceStatus();
		}
	}

	public void readUserData() {
		try {
			if (this.m_pktHdr.pktSize > 0) {
				byte[] arrayOfByte = null;
				arrayOfByte = new byte[this.m_pktHdr.pktSize];
				this.m_ctrlMsg.get(arrayOfByte);
				ByteBuffer localByteBuffer = ByteBuffer.wrap(arrayOfByte);
				localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
				this.userDataPacket = new UserDataPacket(localByteBuffer);
				userData = this.userDataPacket.getUserInfo();
				numUsers = this.userDataPacket.getNumUsers();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public UserDataPacket getUserDataPacket() {
		return this.userDataPacket;
	}

	public static int getNumUsers() {
		return numUsers;
	}

	public static String[] getUserData() {
		return userData;
	}

	public int sendNextMasterInfo(ByteBuffer paramByteBuffer) {
		int i = -1;
		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 50, paramByteBuffer.limit(), (short) 0);
		ByteBuffer localByteBuffer = ByteBuffer.allocate(localIVTPPktHdr.size() + localIVTPPktHdr.pktSize());
		localByteBuffer.position(0);
		localByteBuffer.put(localIVTPPktHdr.array());
		localByteBuffer.put(paramByteBuffer.array());
		localByteBuffer.position(0);
		byte[] arrayOfByte = new byte[localByteBuffer.limit()];
		localByteBuffer.get(arrayOfByte, 0, localByteBuffer.limit());

		i = sendMessage(arrayOfByte, arrayOfByte.length);
		if (arrayOfByte.length != i) {
			return -1;
		}
		return 0;
	}

	public int onSendLockScreen(byte paramByte) {
		byte b = 0;
		b = paramByte;

		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 51, 1, (short) 0);

		ByteBuffer localByteBuffer = ByteBuffer.allocate(localIVTPPktHdr.size() + 1);

		localByteBuffer.position(0);
		localByteBuffer.put(localIVTPPktHdr.array());
		localByteBuffer.put(b);
		localByteBuffer.position(0);

		byte[] arrayOfByte = new byte[localByteBuffer.limit()];
		localByteBuffer.get(arrayOfByte, 0, localByteBuffer.limit());
		if (arrayOfByte.length != sendMessage(arrayOfByte, arrayOfByte.length)) {

			Debug.out.println("Failed to send the lockstatus to the card");
			return -1;
		}

		return 0;
	}

	public short getHostLockStatus() {
		return this.hostLockStatus;
	}

	public void setHostLockStatus(short paramShort) {
		this.hostLockStatus = paramShort;
	}

	public byte getHostLockFeatureStatus() {
		return this.hostLockFeatureStatus;
	}

	public boolean isStopSignalRecieved() {
		return this.stopSignalReceived;
	}

	public int sendKeyBoardLang() {
		String str = JViewer.getKeyboardLayout();
		Debug.out.println("KBD lang" + str);

		IVTPPktHdr localIVTPPktHdr = new IVTPPktHdr((short) 55, str.length(), (short) 0);
		ByteBuffer localByteBuffer = ByteBuffer.allocate(localIVTPPktHdr.size() + localIVTPPktHdr.pktSize());

		localByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
		localByteBuffer.position(0);
		localByteBuffer.put(localIVTPPktHdr.array());
		localByteBuffer.put(str.getBytes());
		localByteBuffer.position(0);

		byte[] arrayOfByte = new byte[localByteBuffer.limit()];
		localByteBuffer.get(arrayOfByte, 0, localByteBuffer.limit());
		if (arrayOfByte.length != sendMessage(arrayOfByte, arrayOfByte.length)) {
			System.out.println("Failed to send the keyboard language to the card");
			return -1;
		}
		return 0;
	}

	private void getVMediaFreeInstanceStatus(ByteBuffer paramByteBuffer) {
		int i = 0;
		int j = 0;
		int k = 0;

		paramByteBuffer.order(ByteOrder.LITTLE_ENDIAN);
		i = paramByteBuffer.getInt();
		j = paramByteBuffer.getInt();
		k = paramByteBuffer.getInt();

		JViewerApp.getInstance().setFreeCDNum(i);
		JViewerApp.getInstance().setFreeFDNum(j);
		JViewerApp.getInstance().setFreeHDNum(k);
		JViewerApp.getInstance().updateFreeDeviceStatus();
	}

	public void setSocketTimeout() {
		if (JViewer.isKVMReconnectEnabled()) {
			try {
				getSocket().setSoTimeout(6000000);

			} catch (SocketException localSocketException) {
				Debug.out.println(localSocketException);
			}
		}
	}

	public boolean isHost_OS_shutdown() {
		return this.Host_OS_shutdown;
	}

	public void setHost_OS_shutdown(boolean paramBoolean) {
		this.Host_OS_shutdown = paramBoolean;
	}

	public int SendKillSession(byte paramByte, int paramInt) {
		int i = 0;
		ByteBuffer localByteBuffer1 = null;
		IVTPPktHdr localIVTPPktHdr = null;

		localByteBuffer1 = ByteBuffer.allocate(5);
		localByteBuffer1.order(ByteOrder.LITTLE_ENDIAN);
		localByteBuffer1.position(0);
		localByteBuffer1.put(paramByte);
		localByteBuffer1.putInt(paramInt);
		localByteBuffer1.rewind();
		localByteBuffer1.position(0);
		localIVTPPktHdr = new IVTPPktHdr((short) 54, localByteBuffer1.limit(), (short) 0);

		ByteBuffer localByteBuffer2 = ByteBuffer.allocate(localIVTPPktHdr.size() + localIVTPPktHdr.pktSize());
		localByteBuffer2.position(0);
		localByteBuffer2.put(localIVTPPktHdr.array());
		localByteBuffer2.put(localByteBuffer1.array());
		localByteBuffer2.position(0);
		byte[] arrayOfByte = new byte[localByteBuffer2.limit()];
		localByteBuffer2.get(arrayOfByte, 0, localByteBuffer2.limit());

		i = sendMessage(arrayOfByte, arrayOfByte.length);
		if (arrayOfByte.length != i) {
			return -1;
		}
		return i;
	}
}

/*
 * Location:
 * D:\Users\tianlin\Downloads\JViewer.jar!\com\ami\kvm\jviewer\kvmpkts\KVMClient
 * .class Java compiler version: 5 (49.0) JD-Core Version: 0.7.1
 */